// 抖音视频数据服务
export const mockDouyinData = {
    // 视频列表数据
    videos: [
        {
            id: '7429611605182221625',  // 抖音视频ID格式
            title: '抖音舞蹈视频合集',
            cover: '/dy.png',
            shareUrl: 'https://v3-dy-o.zjcdn.com/936b0dec529b861b2b5b7730c42cba33/6720a816/video/tos/cn/tos-cn-ve-15c000-ce/owjaxBjaEAe5mFHA3ESi32QOwIwewOijzbC6kf/?a=6383&ch=26&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C3&br=1213&bt=1213&cs=0&ds=3&ft=CZcaELO_DDhNF5VQ9wmEI4ahd.7YdOyR3-ApQX&mime_type=video_mp4&qs=1&rc=NjU8MzNpODRpOTpnODs1NkBpMzhpaHE5cnZudjMzbGkzNEBjLzYyLS4tNWIxLTM2Ni80YSNmYGhnMmRzZGFgLS1kLWJzcw%3D%3D&btag=80000e00008000&cc=1f&cquery=100w_100B_100x_100z_100o&dy_q=1730182627&feature_id=46a7bb47b4fd1280f3d3825bf2b29388&l=202410291417076C0A295E5A440612C6D6&req_cdn_type=', // 分享链接
            author: {
                id: '79265242954',
                name: '抖音舞蹈达人',
                avatar: 'https://p6-sign.douyinpic.com/aweme/100x100/aweme-avatar/tos-cn-avt-0015/7c39b11ef825c3a5',
                verified: true,
            },
            stats: {
                views: '458.5万',
                likes: '22.3万',
                comments: '3089',
                shares: '2.2万',
                collects: '5.4万',
            },
            tags: ['舞蹈', '音乐', '抖音'],
            description: '精选抖音舞蹈视频，欢迎关注！',
            duration: '0:58',
            publishTime: '2024-03-20 15:30:00',
            status: 'normal',
        },
        {
            id: '7429611605182221626',
            title: '抖音美食探店',
            cover: 'https://p9-sign.douyinpic.com/tos-cn-p-0015/oULICGAfjBQADc6gvjNAEv6K8vSvD7FIJGbNaP~tplv-dy-resize-origshort-autoq-75:330.jpeg',
            shareUrl: 'https://v3-dy-o.zjcdn.com/936b0dec529b861b2b5b7730c42cba33/6720a816/video/tos/cn/tos-cn-ve-15c000-ce/owjaxBjaEAe5mFHA3ESi32QOwIwewOijzbC6kf/?a=6383&ch=26&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C3&br=1213&bt=1213&cs=0&ds=3&ft=CZcaELO_DDhNF5VQ9wmEI4ahd.7YdOyR3-ApQX&mime_type=video_mp4&qs=1&rc=NjU8MzNpODRpOTpnODs1NkBpMzhpaHE5cnZudjMzbGkzNEBjLzYyLS4tNWIxLTM2Ni80YSNmYGhnMmRzZGFgLS1kLWJzcw%3D%3D&btag=80000e00008000&cc=1f&cquery=100w_100B_100x_100z_100o&dy_q=1730182627&feature_id=46a7bb47b4fd1280f3d3825bf2b29388&l=202410291417076C0A295E5A440612C6D6&req_cdn_type=', // 分享链接
            author: {
                id: 'dy7m2np9k4v6q8',
                name: '美食达人',
                avatar: 'https://p3-sign.douyinpic.com/aweme/100x100/aweme-avatar/tos-cn-avt-0015/8c39b11ef825c3a5',
                verified: true,
            },
            stats: {
                views: '256.8万',
                likes: '18.9万',
                comments: '2567',
                shares: '1.8万',
                collects: '4.3万',
            },
            tags: ['美食', '探店', '生活'],
            description: '带你探索各地美食，寻找舌尖上的美味！',
            duration: '2:24',
            publishTime: '2024-03-20 14:20:00',
            status: 'normal',
        },
    ],

    // 获取视频列表
    getVideoList() {
        return new Promise((resolve) => {
            setTimeout(() => {
                resolve({
                    list: this.videos,
                    total: this.videos.length,
                })
            }, 300)
        })
    },

    // 获取视频详情
    getVideoDetail(id) {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                const video = this.videos.find((v) => v.id === id)
                if (video) {
                    resolve(video)
                } else {
                    reject(new Error('视频不存在'))
                }
            }, 200)
        })
    },

    // 获取视频统计数据
    getVideoStats(id) {
        return new Promise((resolve) => {
            setTimeout(() => {
                const video = this.videos.find((v) => v.id === id)
                if (video) {
                    // 模拟实时数据变化
                    const randomIncrease = (num) => {
                        const base = parseInt(num.replace(/[^\d]/g, ''))
                        return base + Math.floor(Math.random() * 100)
                    }

                    resolve({
                        ...video.stats,
                        views: randomIncrease(video.stats.views),
                        likes: randomIncrease(video.stats.likes),
                        comments: randomIncrease(video.stats.comments),
                    })
                }
            }, 200)
        })
    },

    // 获取相关视频
    getRelatedVideos(id, limit = 5) {
        return new Promise((resolve) => {
            setTimeout(() => {
                const currentVideo = this.videos.find((v) => v.id === id)
                const relatedVideos = this.videos
                    .filter(
                        (v) =>
                            v.id !== id &&
                            v.tags.some((tag) => currentVideo.tags.includes(tag)),
                    )
                    .slice(0, limit)
                resolve(relatedVideos)
            }, 400)
        })
    },

    // 构建抖音播放器URL
    getVideoUrl(video) {
        // 优先使用分享链接，因为这种格式最稳定
        return video.shareUrl || video.videoUrl || `https://v.douyin.com/video/${video.id}`
    },

    // 模拟视频播放进度
    getVideoProgress(id) {
        return new Promise((resolve) => {
            const progress = localStorage.getItem(`dy-video-progress-${id}`) || '0'
            resolve(parseInt(progress))
        })
    },

    // 保存视频播放进度
    saveVideoProgress(id, progress) {
        return new Promise((resolve) => {
            localStorage.setItem(`dy-video-progress-${id}`, progress.toString())
            resolve(true)
        })
    },
}